#include "SchmidtCAM.h"

int main( int argc, char *argv[] ){

    printf("> (ads5294_reset) start resetting ADS5294 ...\n");

    int fd = open("/dev/mem", O_RDWR | O_SYNC);
    uint *ptr1 = mmap(NULL, 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ADDR_GPIO_OUT);
    uint *gpio_reg      = ptr1;     // 0x41200000
    uint *gpio2_reg     = ptr1+2;   // 0x41200008
    
    uint *ptr2 = mmap(NULL, 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ADDR_GPIO_IN);
    uint *gpio_in_reg   = ptr2;     // 0x41210000

    // SPI config
    SPI_CONFIG *spi_config = (SPI_CONFIG*)malloc(sizeof(SPI_CONFIG));

    setup_SPI_by_device_name( spi_config, "ads5294" );

    SPI_DATA *spi_data = (SPI_DATA*)malloc(sizeof(SPI_DATA));
    spi_data_alloc(spi_data, 1);

    spi_data_set_LS(spi_data, 
                    0, 
                    0X00,
                    0X01,
                    16 );

    send_spi_data(  gpio_reg,
                    gpio2_reg,
                    gpio_in_reg,
                    spi_config, 
                    spi_data );

    free(spi_config);
    
    munmap(ptr1,10);
    munmap(ptr2,10);
    close(fd);

    printf("> (ads5294_reset) finished resetting ADS5294 ...\n");

    return 0;
}
